package com.xinrui.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xinrui.sunnyday.dao.MemberDao;
import com.xinrui.sunnyday.dao.OrderDao;
import com.xinrui.sunnyday.dao.SetmealDao;
import com.xinrui.sunnyday.service.ReportService;
import com.xinrui.sunnyday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderDao orderDao;

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private SetmealDao setmealDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //需要获取当前的日期拿到今日新增的会员、预约数
//        ----------------日期--------------------
        //获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本月一日的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取本月最后一天的日期
        String lastDayOfThisMonth = DateUtils.parseDate2String(DateUtils.getLastDayOfThisMonth());
        //获取本周一的日期
        String thisWeekDay = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本周日的日期
        String lastWeekDay = DateUtils.parseDate2String(DateUtils.getSundayOfThisWeek());

//        ----------------会员--------------------
        //查询今日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //查询本周新增会员
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekDay);
        //查询本月新增会员
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        //查询总会员数
        Integer totalMember = memberDao.findMemberTotalCount();

//        ----------------预约--------------------
        //查询今日新增预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //查询本周新增预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountWeekDate(thisWeekDay,lastWeekDay);
        //查询本月新增预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountMonthDate(firstDay4ThisMonth,lastDayOfThisMonth);
        //获取今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //获取本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekDay);
        //获取本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

//        ----------------热门套餐--------------------
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        Map<String,Object> map = new HashMap<>();
        //添加当前日期
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
